﻿using System;
using System.Web;
using System.Web.Mvc;

using Fuse8.DomainFramework.Common;

namespace Fuse8.ContentManagementFramework.Administration.Controls
{
    public class HttpCmsUserHasNoRightsResult : ActionResult
    {
        public string RedirectUrl { get; set; }

        public HttpCmsUserHasNoRightsResult(string redirectUrl)
        {
            Guard.ArgumentNotEmpty(redirectUrl, "redirectUrl");

            RedirectUrl = redirectUrl;
        }

        public override void ExecuteResult(ControllerContext context)
        {
            Guard.ArgumentNotNull(context, "context");

            string destinationUrl = UrlHelper.GenerateContentUrl(RedirectUrl, context.HttpContext);

            context.Controller.TempData.Keep();

            context.HttpContext.Response.Redirect(destinationUrl, endResponse: true);
        }
    }
}